<?php
declare (strict_types = 1);

namespace app\admin\controller;
use app\validate\OriganziationValidate;
use think\facade\Filesystem;
use think\Request;
use app\model\Origanziation as OModel;
use app\exception\HttpExceptions;
class Origanziation extends AdminAuth
{

    /**
     * @desc 上传图片
     */
    public function upload(Request $request) {
        $file = $request -> file('file');
        $path = Filesystem::disk('public')->putFile( 'origanziation', $file);
        $path = '/storage/'.$path;
        $url = $request->domain(true).$path;
        return $this->result(compact('path','url'));
    }

    /**
     * 删除团体
     */
    public function delete($id) {
        OModel::destroy($id);
        return $this -> result();
    }
     /**
     * 添加修改团体
     */
    public function save(Request $request) {
        $data = $request -> post();
        (new OriganziationValidate()) -> checkParam($data);
        $origan = new OModel();
        if(isset($data['id'])) {
            $origan -> update($data);
        } else {
            $origan->save($data);
        }
        return $this -> result();
    }

     /**
     * 获取学生分页列表
     */

    public function list (Request $request) {
        $data = $request->get(['page','size','kw']);
        if( !isset($data['page'])|| !isset($data['size'])) {
            throw new HttpExceptions('参数不合法');
        }
        $result = OModel::pageList($data);
        return $this->result($result);
    }
}
